# 下载并安装Maven和依赖项
FROM maven:3.6.3-jdk-8-slim AS build

RUN mkdir -p /root/.m2 && \
    echo "<settings><mirrors><mirror><id>alimaven</id><url>http://maven.aliyun.com/nexus/content/groups/public/</url><mirrorOf>*</mirrorOf></mirror></mirrors></settings>" > /root/.m2/settings.xml

WORKDIR /app

COPY pom.xml .

RUN mvn dependency:go-offline

# 编译代码
FROM maven:3.6.3-jdk-8-slim AS compile

WORKDIR /app
COPY --from=build /root/.m2 /root/.m2

COPY src/ ./src/

COPY . .

RUN mvn clean package

# 运行java程序
FROM java:8-jdk-alpine

WORKDIR /app

COPY --from=compile /app/target/*.jar app.jar

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

EXPOSE 8900

CMD ["java", "-jar", "-Xms256m", "-Xmx256m", "app.jar"]
